/****************************************************************************
**
** This file is part of the Qt Extended Opensource Package.
**
** Copyright (C) 2008 Trolltech ASA.
**
** Contact: Qt Extended Information (info@qtextended.org)
**
** This file may be used under the terms of the GNU General Public License
** version 2.0 as published by the Free Software Foundation and appearing
** in the file LICENSE.GPL included in the packaging of this file.
**
** Please review the following information to ensure GNU General Public
** Licensing requirements will be met:
**     http://www.fsf.org/licensing/licenses/info/GPLv2.html.
**
****************************************************************************/

#ifndef PHONEBOOKDIALOG_H
#define PHONEBOOKDIALOG_H

#include <QtGui>
#include <QDir>
#include <QPalette>
#include <QDebug>

#include "ui_phonebookform.h"
#include "neophonebook.h"
#include "addcontactdialog.h"
#include "viewcontactdialog.h"
#include "syncmanager.h"

//============
//#include <QSoftMenuBar>
#include "ringpatternmanager.h"
#include "audiomanager.h"
#include "accelmanager.h"
//#include "syncdialog.h"
//============



class PhoneBookDialog : public QWidget, public Ui_PhoneBookForm
{
    Q_OBJECT
    public:
        enum Update_Types { UP, DOWN, REFRESH, DELETE_LAST };
		enum Mode {NORMAL, SILENT};
        PhoneBookDialog( QWidget *parent = 0, Qt::WFlags f = 0 );
        void updateScreen(Update_Types);
        void updateContactSlot(int index, QString name);
		void loadPattern();
        ~PhoneBookDialog();

        NeoPhoneBook *myPhoneBook;
		RingPatternManager *ringPatternManager;
		AudioManager *audioManager;
		AccelManager *accelManager;
		int mode;

		

    public slots:
        void addContact(NeoPhoneBookEntry *newEntry, bool signal = true);
        void replaceContact(NeoPhoneBookEntry *newEntry, bool signal = true);
        void deleteContact(int index, bool signal = true);
		void deleteContact();
		void on_searchLineEdit_textChanged(const QString &text);
		void on_upButton_clicked();
		void on_downButton_clicked();
		void on_selectButton_clicked();
		void on_deleteButton_clicked();
		void openAddContactDialog();
		void jumpTo(int phoneBookIndex);
		void callContact(bool signal = true);
		void stopCallContact(bool signal = true);
		void finishCallContact();
		void vibrationListener(bool pos, int id);

		void stateChangeListener(int state);
		void validateMode();

		//===== Sync
		void showSyncDialog();
		void updateMenu(int status); // toggle menu for unsync
		void unsync(); // toggle menu for sync


		void addContactListener(NeoPhoneBookEntry *entry);
		void replaceContactListener(int contactIndex, NeoPhoneBookEntry *entry);
		void deleteContactListener(int contactIndex);
		void callContactListener(int contactIndex);
		void stopCallContactListener();

	signals:
		void vibrationSignal(bool pos, int id);
		//===== Sync Action
		void addContactSignal(NeoPhoneBookEntry *entry);
		void replaceContactSignal(int contactIndex, NeoPhoneBookEntry *entry);
		void deleteContactSignal(int contactIndex);
		void callContactSignal(int contactIndex);
		void stopCallContactSignal();
		void closeSignal(int condition);
	
    private:
        int selection;
        QList<int> slotIndex;
		int deviceCount;

		bool hasStateChange;
		QTimer *timer;

		//===== Sync
		//QAction *syncAction;
		//SyncDialog *syncDialog;
		//SyncManager *syncManager;
};

#endif

